/**
 * Copyright 2014 lerry
 * 
 * All right reserved.
 * 
 * Dec 25, 2014
 */
package com.bac.bacplatform;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.os.Handler;

import com.bac.utils.LockPatternUtils;

/**
 * 整个应用启动前的activity，负责几件事<br>
 * 1.显示启动前的介绍页面，也就是loading页<br>
 * 2.负责入口选择：①第一次启动，或者注销过账号，则启动登录页<br>
 * ②已经登录过，则进入主页，主页会重新加载数据
 * 
 * @author lerry
 * 
 */
public class BeforeLoginActivity extends BaseActivity {
//	private LockPatternUtils lockPatternUtils;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash);
//		lockPatternUtils = new LockPatternUtils(this);
		// TODO 现在还没有介绍页，后续待定
		Handler handler = new Handler();
		handler.postDelayed(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				dispatch();
			}
		}, 3000);

	}

	@Override
	public void init() {

	}

	private void dispatch() {
		// 入口分发

		Boolean isFirstIn = true;
		SharedPreferences pref = this.getSharedPreferences("myActivityName", 0);
		// 取得相应的值，如果没有该值，说明还未写入，用true作为默认值
		isFirstIn = pref.getBoolean("isFirstIn", true);
		if (isFirstIn) {
			Intent intentToLoading = new Intent(this, LoadingActivity.class);
			startActivityIn(intentToLoading);
			Editor editor = pref.edit();
			editor.putBoolean("isFirstIn", false);
			editor.commit();
			finish();
			return;
		}else{
			Intent intentToMain = new Intent(BeforeLoginActivity.this,
					MainActivity.class);
			startActivityIn(intentToMain);
			finish();
		}
	}
}
